Re: Apply style to groups of info or to things that need the style?

by Kynn Bartlett <kynn(at)idyllmtn.com>

 Date:  Fri, 26 Jul 2002 13:25:33 -0700
 To:  Complex <complex_hwg(at)yahoo.com>,
HWG Style <hwg-style(at)hwg.org>
 References:  yahoo
  todo: View Thread, Original
At 11:29 AM -0700 7/26/02, Complex wrote:
>1) if I want to center some text, I wrap it in my "center" style:
>       <.div class="center"> Some text <./div >
>where center is defined:
>.center {text-align:center;}
>2) But if I have a group of info, like product names, that need
>centering, I might wrap it in its own style:
>        <.div class="product"> Complex for Mac <./div>
>where product is defined:
>.product {text-align:center; font-size:12pt;}  
>for example.
>
>Which of these is right? And is that just your preference, opinion, or
>do you have some resource backing you up (that is, W3C or someone
>else's opinion)?

The second is much better "style" for style -- while class names are
essentially identifiers with no intrinsic meaning, it's less than
useful to give your class names the same name as an effect you're
trying to create, because then you've broken separation of content
from presentation.

As you say, there are many more benefits for the second approach.
For example, what if you want to change the style of your product
names, so they're no longer centered?  Not to mention the fact that
you may also want to add other styles, such as bold or italic --
and if your class name is center, you'll run into problems when
center actually does 4 different things which may or may not be
centering your text!

I don't believe the W3C has firm statements on class names, but
this is just basic common sense.  I believe you are on the right
track by moving from #1 to #2.

--Kynn

-- 
Kynn Bartlett <kynn(at)idyllmtn.com>                 http://kynn.com
Chief Technologist, Idyll Mountain            http://idyllmtn.com
Next Book: Teach Yourself CSS in 24       http://cssin24hours.com
Kynn on Web Accessibility ->>          http://kynn.com/+sitepoint

HWG hwg-style mailing list archives, maintained by Webmasters @ IWA